package com.hq.ims.data.service;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.dao.AllowLoginPlatformCompanyMapper;
import com.hq.ims.data.entity.AllowLoginPlatformCompany;
import com.hq.ims.data.vo.AllowLoginPlatformCompanyMapstruct;
import com.hq.mybatis.base.BaseService;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.utils.util.ObjectUtils;
import com.hq.web.utils.SpringBootValidateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * @author 蒋柏平
 * @since 20241028
 * @detail 允许登陆平台的公司 服务实现类
 */
@Service
public class BaseAllowLoginPlatformCompanyService extends BaseService<AllowLoginPlatformCompanyMapper, AllowLoginPlatformCompany> {


    /**
    * 分页
    */
    public List<AllowLoginPlatformCompanyMapstruct.AllowLoginPlatformCompanyVo> getByPage(
            RequestPage page,
            AllowLoginPlatformCompanyMapstruct.PageSearchVo searchVo
    ) {
        //验证
        LambdaQueryChainWrapper<AllowLoginPlatformCompany> lq = this.lambdaQuery();
        //排序
        //查询条件

        //执行分页
        lq.page(page);

        List<AllowLoginPlatformCompany> dataList = page.getRecords();
        List<AllowLoginPlatformCompanyMapstruct.AllowLoginPlatformCompanyVo> voList = AllowLoginPlatformCompanyMapstruct.INSTANCE.toAllowLoginPlatformCompanyVoList(dataList);
        page.setRecords(voList);
        return voList;
    }

    /**
      * 添加
      */
    @Transactional(rollbackFor = Exception.class)
    public AllowLoginPlatformCompany addData(AllowLoginPlatformCompanyMapstruct.SaveVo vo) {
        //验证
        SpringBootValidateUtils.validate(vo,VdAdd.class);

        //账值新的对象
        AllowLoginPlatformCompany entity = new AllowLoginPlatformCompany();

         entity.insert();
         return entity;
    }

     /**
     * 编辑
     */
     @Transactional(rollbackFor = Exception.class)
     public AllowLoginPlatformCompany editData(AllowLoginPlatformCompanyMapstruct.SaveVo vo) {
         //验证
        SpringBootValidateUtils.validate(vo,VdEdit.class);

        //账值新的对象
        AllowLoginPlatformCompany entity = this.getById(vo.getAllowLoginPlatformCompanyId());
        ObjectUtils.isNullThrow(entity, "数据不存在");


        entity.updateById();
        return entity;
     }


    /**
    * 删除
    */
    @Transactional(rollbackFor = Exception.class)
    public void delData(String allowLoginPlatformCompanyId) {
        AllowLoginPlatformCompany data = this.getById(allowLoginPlatformCompanyId);
        if(data == null){
            return;
        }
        data.deleteById();
    }

    /**
     * 获取原始数据详情
     */
    public AllowLoginPlatformCompanyMapstruct.AllowLoginPlatformCompanyVo getDetailVo(String allowLoginPlatformCompanyId) {
        AllowLoginPlatformCompany entity = this.getById(allowLoginPlatformCompanyId);
        AllowLoginPlatformCompanyMapstruct.AllowLoginPlatformCompanyVo vo = AllowLoginPlatformCompanyMapstruct.INSTANCE.toAllowLoginPlatformCompanyVo(entity);
        return vo;
    }
}